import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author LiuYan
 * @date 2021/11/15 8:50
 */
public class Part09 {
    /**
     * Date里面的一些方法过时了
     */
    public static void main(String[] args) throws ParseException {

        Calendar now = Calendar.getInstance();

        // 获取年月日时分秒
        int year = now.get(Calendar.YEAR);
        int moth = now.get(Calendar.MONTH);// 获取当前月份索引（0-11）
        int day = now.get(Calendar.DAY_OF_MONTH);
        int hour = now.get(Calendar.HOUR);
        int minute = now.get(Calendar.MINUTE);
        int second = now.get(Calendar.SECOND);
        System.out.println(year);
        System.out.println(moth);
        System.out.println(day);
        System.out.println(hour);
        System.out.println(minute);
        System.out.println(second);
        // 设置时间
        now.set(2022, 12, 12, 12, 12, 12);
        now.set(Calendar.YEAR,2222);
        // Date---->Calendar
        now.setTime(new Date());
        // Calendar---->Date
        Date time = now.getTime();
        System.out.println(time);
        // Calendar添加字段(添加两个月)
        now.add(Calendar.MONTH,2);
        // String---->Date
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy--MM-dd HH:mm:ss");
        String str="2021-12-12 00:00:00";
        simpleDateFormat.parse(str);
        // Date---->String
        Date date=new Date();
        String format = simpleDateFormat.format(date);
        System.out.println(format);


    }
}
